home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / text / misc / mpage.lha / mpage / mpage.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-25  |  10.2 KB  |  352 lines

  1. /*
  2.  * mpage.h
  3.  */
  4.  
  5. /*
  6.  * mpage:    A program to reduce pages of print so that several pages
  7.  *           of output appear on one sheet of paper.
  8.  *
  9.  * Copyright (c) 1988 Mark P. Hahn, Herndon, Virginia
  10.  * Copyright (c) 1994-1997 Marcel J.E. Mol, The Netherlands
  11.  *                    marcel@mesa.nl
  12.  *  
  13.  * Written by:
  14.  *   ...!uunet!\                       Mark Hahn, Sr Systems Engineer
  15.  *              >pyrdc!mark            Pyramid Technology Corporation
  16.  * ...!pyramid!/                       Vienna, Va    (703)848-2050
  17.  *
  18.  *
  19.  *     Permission is granted to anyone to make or distribute verbatim
  20.  *     copies of this document as received, in any medium, provided
  21.  *     that this copyright notice is preserved, and that the
  22.  *     distributor grants the recipient permission for further
  23.  *     redistribution as permitted by this notice.
  24.  *
  25.  */
  26.  
  27. /*
  28.  * Through-out the program comments I have tried to refer to pages a the
  29.  * logical printed page of text that gets reduced.  Sheets refer to physical
  30.  * pieces of paper.  Hence, mulitple pages appear on a sheet.  "page" is a
  31.  * logical or virtual entity, and "sheet" is physical entity.
  32.  */
  33.  
  34. #include <unistd.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37.  
  38. # define    VERSION        "2.5 November 1997"
  39.  
  40. # define    TRUE        1
  41. # define    FALSE        0
  42.  
  43. # define    LINESIZE    1024
  44.  
  45. # define    FILE_EOF    1
  46. # define    FILE_MORE    2
  47.  
  48. # define    LINE_MORE    5
  49. # define    LINE_EOF_NOW    4
  50. # define    LINE_EOF    3
  51. # define    LINE_OVERPRINT    2
  52. # define    LINE_BLANK    1
  53.  
  54. # define    TSIZE        12
  55. # define     HSIZE        TSIZE+2
  56.  
  57. # define       DEFAULTPMARGIN  4
  58. #if !defined(DEFAULTSMARGIN)
  59. # define        DEFAULTSMARGIN  20
  60. #endif
  61. # define        DEFAULTTMARGIN  0
  62. # define        DEFAULTTABSTOP  8
  63.  
  64. #ifdef MAXINT /* ARK */
  65. #undef MAXINT
  66. #endif
  67.  
  68. # define    MAXINT        (1 << 30)
  69. #if !defined(DEFAULT_ENCODING)
  70. # define        DEFAULT_ENCODING  0
  71. #endif
  72.  
  73. /*
  74.  * to turn on debugging, define the preprocessor macro DEBUG and set
  75.  * the variable Debug_flag to the sum of the sections to debug.
  76.  */
  77. # ifdef DEBUG
  78. # define Debug(f,s,a)    if (Debug_flag & f) printf(s,a)
  79. # define DB_GETLINE    0x0000001
  80. # define DB_ONEPAGE    0x0000002
  81. # define DB_STDIN    0x0000004
  82. # define DB_PSDOC    0x0000008
  83. # define DB_PSPAGE    0x0000010
  84. # define DB_PSCHECK    0x0000020
  85. # define DB_PSROFF    0x0000040
  86. # define DB_PSMPAGE    0x0000080
  87. # define DB_POINTS    0x0000100
  88. # define DB_POST    0x0000200
  89. # define DB_UNUSED    0x0000400
  90. extern int Debug_flag;
  91. extern int errno;
  92. # else
  93. # define Debug(f,s,a)
  94. # endif /* DEBUG */
  95.  
  96. /*
  97.  * definitions for sorting out types of postscript input
  98.  */
  99. # define    PS_NONE        0
  100. # define    PS_PSROFF    1
  101. # define    PS_MPAGE    2
  102. # define    PS_CONFORM    3
  103. # define    PS_OTHER    4
  104. # define    PS_MSWINDOWS    5
  105. # define    PS_TEX        6
  106. # define    PS_TEX2        7
  107.  
  108.  
  109. /*
  110.  * Input file type selection types
  111.  */
  112. # define    IN_AUTO        0
  113. # define    IN_ASCII    1
  114. # define    IN_PS        2
  115.  
  116.  
  117. /*
  118.  * define page sizes
  119.  */
  120. #define PAGE_A4        1
  121. #define PAGE_LETTER    2
  122. #define PAGE_LEGAL     3
  123. #define PAGE_A3        4
  124. #if !defined(PAGE_DEF)
  125. # define PAGE_DEF    PAGE_A4
  126. #endif
  127.  
  128. /*
  129.  * define print spooler types
  130.  */
  131. #define ATT_SPOOLER    1
  132. #define BSD_SPOOLER    2
  133. #if !defined(SPOOLER)
  134. # define SPOOLER    BSD_SPOOLER
  135. #endif
  136.  
  137. /*
  138.  * printing definitions
  139.  */
  140. #if !defined(PRPROG)
  141. # define PRPROG        "pr"
  142. #endif
  143. #if !defined(PRINTPROG)
  144. # if SPOOLER == ATT_SPOOLER
  145. #  define PRINTPROG   "lp"
  146. # else /* BSD_SPOOLER */
  147. #  define PRINTPROG   "lpr"
  148. # endif
  149. #endif
  150. #if !defined(QUEARG)
  151. # if SPOOLER == ATT_SPOOLER
  152. #  define QUEARG              "-d"
  153. # else /* BSD_SPOOLER */
  154. #  define QUEARG              "-P"
  155. # endif
  156. #endif
  157.  
  158. /*
  159.  * "Conforming" postscript flag string  (remember ps_check strips
  160.  * the "%!" flag from PS files
  161.  */
  162. # define    PS_FLAG        "PS"
  163. # define    PS_FLAG2    "-Adobe-"
  164.  
  165. /*
  166.  * some basic PS parameters
  167.  */
  168. extern int ps_width;    /* number of points in the X direction (8.5 inches) */
  169. extern int ps_height;    /* number of points in the Y direction (11 inches) */
  170. extern char * media;    /* name of output page media */
  171.  
  172. /*
  173.  * a sheet describes the measurements and orientatation of a page for
  174.  * use in constructing a sheet preabmles.
  175.  */
  176. struct sheet {
  177.     int sh_cwidth;        /* number of characters across a page */
  178.     int sh_plength;        /* number of lines down a page */
  179.     int (*sh_width)();    /* postscript width across a printed page */
  180.     int (*sh_height)();    /* postscript height of a printed page */
  181.     int sh_rotate;        /* angle to rotate the page */
  182.     void (*sh_outline)();    /* text to print as outline for */
  183.                 /*    the printed sheet*/
  184.     struct    pagepoints *sh_pagepoints; /* where to put pages on */
  185.                          /*    the printed sheet */
  186. };
  187.  
  188. /*
  189.  * simple x and y coordinates for putting pages of output on printed sheet
  190.  * skip to skip this page???
  191.  */
  192. struct pagepoints {
  193.     int (*pp_origin_x)();
  194.     int (*pp_origin_y)();
  195.     int skip;
  196. };
  197.  
  198. /*
  199.  * Definition of an optional annotate box around part of text
  200.  */
  201. struct pagebox {
  202.     int over; /* over from the left column */
  203.     int lift; /* lift from the bottom line */
  204.     int wide; /* columns wide */
  205.     int high; /* lines high */
  206.     int thick;/* line thickness */
  207. };
  208.  
  209. /* array of sheets where pages are ordered for coli ??? */
  210. extern struct sheet coli[];
  211.  
  212. /* array of sheets where pages are ordered for left to right reading */
  213. extern struct sheet *left_right[];
  214.  
  215. /* arrays for sheets where pages are ordered for top to bottom reading  */
  216. extern struct sheet *up_down[];
  217.  
  218. /* definitions for aspect and reading directions */
  219. # define PORTRAIT    0
  220. # define LANDSCAPE    1
  221. # define LANDSCAPE_PORTRAIT    2
  222. # define UPDOWN        0
  223. # define LEFTRIGHT    1
  224.  
  225. /*
  226.  * Variables for holding the chosen options,  The defaults are set here.
  227.  * the sheetlist pointer is set to point to the array for either up/down
  228.  * or left/right reading.  This array is index by sheetorder, and then
  229.  * sheetindex.  sheetindex encodes the number of reduced pages per printed
  230.  * sheet and indexes into the sheet list (0 = 1 page, 1 = two pages, 2 =
  231.  * four pages, 3 = eight pages).
  232.  */
  233. extern struct sheet **sheetlist;/* array of sheet lists (up/down or left/right) */
  234. extern int sheetaspect;        /* either normal or landscape */
  235. extern int sheetorder;        /* up/down or left/right flag */
  236. extern int sheetindex;        /* index to number of pages of sheet */
  237. extern int sheetmargin_left;    /* non-printable border on sheet */
  238. extern int sheetmargin_right;    /* non-printable border on sheet */
  239. extern int sheetmargin_top;    /* non-printable border on sheet */
  240. extern int sheetmargin_bottom;    /* non-printable border on sheet */
  241. extern int pagemargin_left;    /* border for pages */
  242. extern int pagemargin_right;    /* border for pages */
  243. extern int pagemargin_top;    /* border for pages */
  244. extern int pagemargin_bottom;    /* border for pages */
  245. extern int textmargin_left;    /* border for textbox */
  246. extern int textmargin_right;    /* border for textbox */
  247. extern int textmargin_top;    /* border for textbox */
  248. extern int textmargin_bottom;    /* border for textbox */
  249. extern int sheetheader_left;    /* space for physical sheetheader */
  250. extern int sheetheader_right;   /* space for physical sheetheader */
  251. extern int sheetheader_top;     /* space for physical sheetheader */
  252. extern int sheetheader_bottom;  /* space for physical sheetheader */
  253.  
  254. extern struct pagepoints *points;
  255. extern int orientation;        /* final orientation of text */
  256. extern int fsize;        /* font scale size */
  257. extern int opt_pr;        /* boolean, if true use pr to format output */
  258. extern int opt_tabstop;        /* define tabstop width */
  259. extern int opt_indent;        /* starting column for text printing */
  260. extern int opt_lines;        /* number of lines to fit on an reduced page */
  261. extern int opt_width;        /* number of columns to fit on reduced page */
  262. extern int opt_mp_header;    /* let mapge create a header */
  263. extern int  opt_sheetheader;    /* let mpage create sheetheaders */
  264. extern int opt_page;        /* sheets size: a4 or us letter */
  265. extern int opt_fold;        /* fold long lines */
  266. extern int opt_outline;        /* print a nice outline around pages */
  267. extern int opt_verbose;        /* print a count of pages sent to printer */
  268. extern int opt_square;        /* Make pages with same aspect as sheets */
  269. extern int opt_reverse;        /* Print sheets in reverse order */
  270. extern int opt_first;        /* First sheet # to print, 1 = first */
  271. extern int opt_last;        /* Last sheet # to print, 0 = EOF */
  272. extern int opt_alt;        /* Print every Nth sheet */
  273. extern int opt_file;            /* should each file appera on a new sheet */
  274. extern int opt_duplex;          /* duplex mode*/
  275. extern int opt_tumble;          /* tumble every second pages */
  276. extern int opt_textbox;         /* print a nice box box around text*/
  277. extern int opt_input;           /* set input file type */
  278. extern int opt_encoding;        /* use default encoding or not */
  279.  
  280. extern struct pagebox textbox;
  281.  
  282.  
  283. extern char * opt_header;    /* the header for pr's -h option */
  284. extern char * printque;        /* the printer queuename */
  285. extern char * prprog;        /* the pr filter program */
  286. extern char * printprog;    /* the print program */
  287. extern char * printarg;        /* define print queue to printprog */
  288. extern int    doprint;        /* send output to printer or not */
  289. extern char * charvec_file;    /* file to read character definitions from */
  290. extern char * libdir;        /* pointer to get library files from */
  291. extern char * fontname;        /* Font to use */
  292. extern char * dateformat;    /* Date/time format for headers */
  293. extern char * sheethead;    /* Header for each physical page */
  294.  
  295.  
  296. /*
  297.  * various global information
  298.  */
  299. extern char MPAGE[];        /* program name */
  300. extern int ps_pagenum;        /* current page count */
  301. extern int had_ps;              /* did we process ps files */
  302. extern int first_encoding;    /* first encoding in character set */
  303. extern int last_encoding;    /* last encoding in character set */
  304. extern int mpage_level;        /* keep track of multilevel mpaga calls */
  305. extern int Coli;        /* value of 0=don't mess, 1 = 4,1 (outside pages), */
  306.  
  307.  
  308. /* args.c */
  309. int do_args();
  310. int do_env();
  311. /* file.c */
  312. void do_file();
  313. void do_pr_file();
  314. void do_stdin();
  315. void do_sheets();
  316. /* glob.c */
  317. void usage();
  318. /* page.c */
  319. void set_page();
  320. int xbase1(), xbase2();
  321. int ybase1(), ybase2(), ybase3(), ybase4();
  322. int ytop1(), ytop2(), ytop3(), ytop4();
  323. int xwid1(), xwid2();
  324. int yht1(), yht2(), yht4();
  325. void outline_1();       
  326. void outline_2();       
  327. void outline_4();       
  328. void outline_8();       
  329. void sheetheader();
  330. void mp_outline();
  331. /* post.c */
  332. int ps_check();
  333. void do_ps_doc();
  334. /* text.c */
  335. void do_text_doc();
  336.  
  337. /*
  338.  * For OS/2
  339.  */
  340. #ifdef __EMX__
  341. # define strcasecmp stricmp
  342. #endif
  343.  
  344. /*
  345.  * For Amiga
  346.  */
  347. #ifdef AMIGA
  348. #define popen      fopen
  349. #define pclose     fclose
  350. #define strcasecmp stricmp
  351. #endif
  352.